package model

import (
	"chitchat_http/util"
	"github.com/doujunyu/gogo/gogo_log"
	"github.com/doujunyu/gogo/sql_aid"
)

const TableByChatGroupFriend = "self_chat_group_friend"

const ChatGroupFriendByIdentityIdOrdinary = 0 //普通成员
const ChatGroupFriendByIdentityIdManager = 1 //群主
const ChatGroupFriendByIdentityIdAdministrator = 2 //管理员


// ChatGroupFriendByUserCheck 群组内可以审核的用户
func ChatGroupFriendByUserCheck (groupId int64)[]map[string]interface{}{
	groupFriendSql,args := sql_aid.PgTable(TableByChatGroupFriend).Field("id","user_id","identity_id").Where("group_id = ?",groupId).WhereIn("identity_id",ChatGroupFriendByIdentityIdManager,ChatGroupFriendByIdentityIdAdministrator).ToSql()
	groupFriendSqlData,err := sql_aid.DataToMap(PgSql.Query(groupFriendSql,args...))
	if err != nil {
		gogo_log.Error("model_ChatGroupFriendByUserCheck", "查询是群组sql失败", err.Error())
		return []map[string]interface{}{}
	}
	return groupFriendSqlData
}

// ChatGroupFriendByGroupAllUserId 群组所有成员
func ChatGroupFriendByGroupAllUserId(groupId int64)[]interface{}{
	//群组所有成员
	groupFriendSql,args := sql_aid.PgTable(TableByChatGroupFriend).Field("user_id").Where("group_id = ?",groupId).ToSql()
	groupFriendData,err := sql_aid.DataToMap(PgSql.Query(groupFriendSql,args...))
	if err != nil {
		gogo_log.Error("model_ChatGroupFriendByGroupAllUserId", "查询数据失败", err.Error())
		return []interface{}{}
	}
	return util.ArrayField(&groupFriendData,"user_id")
}
